﻿' Note: For instructions on enabling IIS6 or IIS7 classic mode, 
' visit http://go.microsoft.com/?LinkId=9394802

Imports System.ComponentModel

Public Class MvcApplication
    Inherits System.Web.HttpApplication

    Shared Sub RegisterGlobalFilters(ByVal filters As GlobalFilterCollection)
        filters.Add(New ElmahHandleErrorAttribute())
        filters.Add(New HandleErrorAttribute())
    End Sub

    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
        routes.IgnoreRoute("{resource}.ico")
        routes.IgnoreRoute("robots.txt")

        ' MapRoute takes the following parameters, in order:
        ' (1) Route name
        ' (2) URL with parameters
        ' (3) Parameter defaults
        routes.MapRoute( _
            "Default", _
            "{controller}/{action}/{id}", _
            New With {.controller = "Aviso", .action = "Lista", .id = UrlParameter.Optional} _
        )

    End Sub

    Sub Application_Start()
        AreaRegistration.RegisterAllAreas()
        RegisterGlobalFilters(GlobalFilters.Filters)
        RegisterRoutes(RouteTable.Routes)
        DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = False
        ModelValidatorProviders.Providers.Add(New FluentValidation.Mvc.FluentValidationModelValidatorProvider(New FluentValidation.Attributes.AttributedValidatorFactory))

        AutoMapper.Mapper.CreateMap(Of Sociedad, GridSociedadModel)

        AutoMapper.Mapper.CreateMap(Of GridSociedadModel, Sociedad)()

    End Sub

    Shared Function MyPropertyNameResolver(ByVal tipo As Type, ByVal miembro As System.Reflection.MemberInfo) As String
        If miembro IsNot Nothing Then
            Dim displayNames = miembro.GetCustomAttributes(GetType(DisplayNameAttribute), True)
            If displayNames.Count > 0 Then
                Return DirectCast(displayNames(0), DisplayNameAttribute).DisplayName
            Else
                Return miembro.Name
            End If
        Else
            Return Nothing
        End If
    End Function

End Class
